//
//  MPBTools+Notification.m
//  MiaoPai
//
//  Created by jiaxuzhou on 2017/6/10.
//  Copyright © 2017年 Jeakin. All rights reserved.
//
//


#import "MPBTools+Notification.h"
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCall.h>
#import "MPTNotificationKey.h"

static CTCallCenter *ctCenter = nil;


@implementation MPBTools (Notification)

+ (void)load
{
    CTCallCenter *center = [[CTCallCenter alloc] init];
    ctCenter = center;
    ctCenter.callEventHandler = ^(CTCall *call)
    {
        if ([call.callState isEqualToString:CTCallStateDisconnected])
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:MPT_NotifKey_CTCallStateDisconnected object:nil];
        }
        else if ([call.callState isEqualToString:CTCallStateConnected])
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:MPT_NotifKey_CTCallStateConnected object:nil];
        }
        else if([call.callState isEqualToString:CTCallStateIncoming])
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:MPT_NotifKey_CTCallStateIncoming object:nil];
        }
        else if ([call.callState isEqualToString:CTCallStateDialing])
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:MPT_NotifKey_CTCallStateDialing object:nil];
        }
    };
}


/**
 注释

 @param observer 注释
 @param aSelector 注释
 @param aName 注释
 @param anObject 注释
 */
- (void)addObserver:(id)observer
           selector:(SEL)aSelector
               name:(NSString *)aName
             object:(nullable id)anObject
{
    [[NSNotificationCenter defaultCenter] addObserver:observer
                                             selector:aSelector
                                                 name:aName
                                               object:anObject];
}

- (void)postNotificationName:(NSString *)aName
                      object:(nullable id)anObject
{
    [[NSNotificationCenter defaultCenter] postNotificationName:aName
                                                        object:anObject];
}

- (void)postNotificationName:(NSString *)aName
                      object:(nullable id)anObject
                    userInfo:(nullable NSDictionary *)aUserInfo
{
    [[NSNotificationCenter defaultCenter] postNotificationName:aName
                                                        object:anObject
                                                      userInfo:aUserInfo];
}

- (void)postNotification:(NSNotification *)notification
{
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}

- (void)removeObserver:(id)observer
{
    [[NSNotificationCenter defaultCenter] removeObserver:observer];
}

- (void)removeObserver:(id)observer
                  name:(nullable NSString *)aName
                object:(nullable id)anObject
{
    [[NSNotificationCenter defaultCenter] removeObserver:observer
                                                    name:aName
                                                  object:anObject];
}


@end
